﻿@inherits BaseComponent

@if (Context.IsEditTable && Model?.Table?.EnableEdit == true)
{
    <div class="kui-edit" style="margin-right:10px;" @onclick="OnEditTool">
        <KIcon Icon="edit" Title="@Language.EditToolbar" />
    </div>
}
@if (Model != null && (Model.Left != null || Model.Right != null || Model.HasItem))
{
    var items = Model.Items.GetGroupItems();
    <div class="ant-toolbar">
        @Model.Left
        @if (Model.HasItem)
        {
            if (items.Count > Model.ShowCount)
            {
                for (int i = 0; i < Model.ShowCount - 1; i++)
                {
                    var item = items[i];
                    @RenderButton(item)
                }
                var more = GetDropdownModel(Language.More);
                more.Items = items.Skip(Model.ShowCount - 1).ToList();
                <AntDropdown Context="Context" Model="more" />
            }
            else
            {
                foreach (var item in items)
                {
                    @RenderButton(item)
                }
            }
        }
        @Model.Right
    </div>
}

@code {
    private RenderFragment RenderButton(ActionInfo item)
    {
        if (item.Children != null && item.Children.Count > 0)
        {
            var model = GetDropdownModel(item);
            model.Items = item.Children;
            return @<AntDropdown Context="Context" Model="model" />;
        }
        else
        {
            return @<KButton Name="@item.Name" Enabled="item.Enabled" Type="item.ToType()" Danger="item.IsDanger()" Icon="@item.Icon" Title="@item.Title" Badge="item.Badge" OnClick="e=>Model.OnItemClick?.Invoke(item)" />;
        }
    }
}